package cn.qyd.hashmap;

import java.util.HashMap;

/**
 * @author 邱运铎
 * @date 2024-03-13 17:49
 */
public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<String,String> hashMap = new HashMap();
        hashMap.put(null,null);
        System.out.println(hashMap.get(0));
        System.out.println(hashMap.get(null));

        hashMap.put("zhangsan","张三");
        hashMap.put("lisi","李四");
        hashMap.put("wangwu","王五");
        hashMap.put("zhaoliu","赵六");
        hashMap.put("qiuyunduo","邱运铎");

        int h , n = 16;
        for (String key : hashMap.keySet()) {
            int hash = (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
            int index = hash&(n-1);
            System.out.println("hashmap中元素： {" + key + "}  的hash值为： " + hash);
            System.out.println("hashmap中元素： {" + key + "}  的h下标为： " + index);
        }

    }

    public int hash(Object key) {
        int h;
        return key == null ? 0 : (h=key.hashCode()) ^ (h >>> 16);
    }
}
